<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./OL_SDK/include-openlayers-local.js"></script>
    <script src="./libs/gaode.js"></script>
</head>

<body>
    <button id="btn" onclick="activeMap()">激活地图事件</button>
    <button onclick="remmoveMap()">移除地图事件</button>
    <div id="map">
    </div>
    <script>
        var map = new ol.Map({
            target: "map",
            layers: [gaode],
            view: new ol.View({
                projection: 'EPSG:4326',
                center: [114.30, 30.50],
                zoom: 4
            })
        })
        /* 设置空的实例数据源图层 */
        let style = new ol.style.Style({
            //形状
            image: new ol.style.Circle({
                /* radius 设置半径 */
                radius: 30,
                fill: new ol.style.Fill({
                    color: '#ffcc33'
                }),
                stroke: new ol.style.Stroke({
                    color: "#333",
                    width: 5
                })
            })
        })
        const source = new ol.source.Vector({})
        const layer = new ol.layer.Vector({
            source,
            style
        })
        map.addLayer(layer)
        var btn = document.getElementById("btn")
        function activeMap() {
            /* 灰色 */
            btn.disabled = true;
            btn.style.cursor = "no-drop"
            map.on("click", handleClick)
        }
        function remmoveMap() {
            map.un("click", handleClick);
            source.clear()
            /* 让按钮正常 */
            btn.disabled = false;
            btn.style.cursor = "default";
        }
        function handleClick(evt) {
            console.log(evt)
            let point = new ol.Feature({
                geometry: new ol.geom.Point(evt.coordinate)
            })
            source.addFeature(point)
        }
    </script>
</body>

</html>